Move the get_cursor_color in GtkStyleContext
authorPaolo Borelli <pborelli@gnome.org>
Sat, 29 Jan 2011 11:47:09 +0000 (12:47 +0100)
committerPaolo Borelli <pborelli@gnome.org>
Sat, 29 Jan 2011 12:13:42 +0000 (13:13 +0100)
Move the private get_cursor_color method belongs to StyleContext. Change
the api so that retrieving both primary and secondary color is possible.
I left the method private for now, though it should probably be public
as all the other getters.

gtk/gtkentry.c
gtk/gtkstyle.c
gtk/gtkstylecontext.c
gtk/gtkstylecontextprivate.h
gtk/gtktextdisplay.c
gtk/gtkwidgetprivate.h

index a54f821a10bd97fa26c16970f30e2961ef4ec406..f40df25c3bb04b41e7f9345670dc74ca85c92358 100644 (file)
@@ -66,7 +66,7 @@
 #include "gtkiconfactory.h"
 #include "gtkicontheme.h"
 #include "gtkwidgetprivate.h"
-
+#include "gtkstylecontextprivate.h"
 
 /**
  * SECTION:gtkentry
@@ -5805,6 +5805,7 @@ gtk_entry_draw_cursor (GtkEntry  *entry,
     }
   else /* overwrite_mode */
     {
+      GtkStyleContext *context;
       GdkRGBA cursor_color;
       GdkRectangle rect;
       gint x, y;
@@ -5818,18 +5819,18 @@ gtk_entry_draw_cursor (GtkEntry  *entry,
       rect.width = PANGO_PIXELS (cursor_rect.width);
       rect.height = PANGO_PIXELS (cursor_rect.height);
 
-      _gtk_widget_get_cursor_color (widget, &cursor_color);
+      context = gtk_widget_get_style_context (widget);
+
+      _gtk_style_context_get_cursor_color (context, &cursor_color, NULL);
       gdk_cairo_set_source_rgba (cr, &cursor_color);
       gdk_cairo_rectangle (cr, &rect);
       cairo_fill (cr);
 
       if (!block_at_line_end)
         {
-          GtkStyleContext *context;
           GtkStateFlags state;
           GdkRGBA color;
 
-          context = gtk_widget_get_style_context (widget);
           state = gtk_widget_get_state_flags (widget);
           gtk_style_context_get_background_color (context, state, &color);
 
index a234a34d2312056dd1d7687ca298bde703f96ff7..16dafc6f3a21c541236dc001560a66a12ccf7584 100644 (file)
@@ -42,7 +42,6 @@
 #include "gtkspinner.h"
 #include "gtkborder.h"
 
-
 /**
  * SECTION:gtkstyle
  * @Short_description: An object that hold style information for widgets
@@ -3971,55 +3970,6 @@ gtk_paint_spinner (GtkStyle           *style,
   cairo_restore (cr);
 }
 
-static void
-get_cursor_color (GtkStyleContext *context,
-                  gboolean         primary,
-                  GdkRGBA         *color)
-{
-  GdkColor *style_color;
-
-  gtk_style_context_get_style (context,
-                               primary ? "cursor-color" : "secondary-cursor-color",
-                               &style_color,
-                               NULL);
-
-  if (style_color)
-    {
-      color->red = style_color->red / 65535;
-      color->green = style_color->green / 65535;
-      color->blue = style_color->blue / 65535;
-      color->alpha = 1;
-
-      gdk_color_free (style_color);
-    }
-  else
-    {
-      gtk_style_context_get_color (context, GTK_STATE_FLAG_NORMAL, color);
-
-      if (!primary)
-      {
-        GdkRGBA bg;
-
-        gtk_style_context_get_background_color (context, GTK_STATE_FLAG_NORMAL, &bg);
-
-        color->red = (color->red + bg.red) * 0.5;
-        color->green = (color->green + bg.green) * 0.5;
-        color->blue = (color->blue + bg.blue) * 0.5;
-      }
-    }
-}
-
-void
-_gtk_widget_get_cursor_color (GtkWidget *widget,
-                              GdkRGBA   *color)
-{
-  GtkStyleContext *context;
-
-  context = gtk_widget_get_style_context (widget);
-
-  get_cursor_color (context, TRUE, color);
-}
-
 /**
  * gtk_draw_insertion_cursor:
  * @widget:  a #GtkWidget
@@ -4050,7 +4000,8 @@ gtk_draw_insertion_cursor (GtkWidget          *widget,
   gfloat cursor_aspect_ratio;
   gint offset;
   GtkStyleContext *context;
-  GdkRGBA color;
+  GdkRGBA primary_color;
+  GdkRGBA secondary_color;
 
   g_return_if_fail (GTK_IS_WIDGET (widget));
   g_return_if_fail (cr != NULL);
@@ -4059,8 +4010,8 @@ gtk_draw_insertion_cursor (GtkWidget          *widget,
 
   context = gtk_widget_get_style_context (widget);
 
-  get_cursor_color (context, is_primary, &color);
-  gdk_cairo_set_source_rgba (cr, &color);
+  _gtk_style_context_get_cursor_color (context, &primary_color, &secondary_color);
+  gdk_cairo_set_source_rgba (cr, is_primary ? &primary_color : &secondary_color);
 
   /* When changing the shape or size of the cursor here,
    * propagate the changes to gtktextview.c:text_window_invalidate_cursors().
index c61964f243bf0c67a8acc4f95f5c79367e4edc39..7cd0dab1c1650150bc6b85331b0ebfad38978564 100644 (file)
@@ -3596,6 +3596,56 @@ gtk_style_context_get_font (GtkStyleContext *context,
   return NULL;
 }
 
+static void
+get_cursor_color (GtkStyleContext *context,
+                  gboolean         primary,
+                  GdkRGBA         *color)
+{
+  GdkColor *style_color;
+
+  gtk_style_context_get_style (context,
+                               primary ? "cursor-color" : "secondary-cursor-color",
+                               &style_color,
+                               NULL);
+
+  if (style_color)
+    {
+      color->red = style_color->red / 65535;
+      color->green = style_color->green / 65535;
+      color->blue = style_color->blue / 65535;
+      color->alpha = 1;
+
+      gdk_color_free (style_color);
+    }
+  else
+    {
+      gtk_style_context_get_color (context, GTK_STATE_FLAG_NORMAL, color);
+
+      if (!primary)
+      {
+        GdkRGBA bg;
+
+        gtk_style_context_get_background_color (context, GTK_STATE_FLAG_NORMAL, &bg);
+
+        color->red = (color->red + bg.red) * 0.5;
+        color->green = (color->green + bg.green) * 0.5;
+        color->blue = (color->blue + bg.blue) * 0.5;
+      }
+    }
+}
+
+void
+_gtk_style_context_get_cursor_color (GtkStyleContext *context,
+                                     GdkRGBA         *primary_color,
+                                     GdkRGBA         *secondary_color)
+{
+  if (primary_color)
+    get_cursor_color (context, TRUE, primary_color);
+
+  if (secondary_color)
+    get_cursor_color (context, FALSE, secondary_color);
+}
+
 /* Paint methods */
 
 /**
index de703083315d9e8ab964309280c510e12190014e..57db77e5cb6b44b9613d48b51d1065ee05b99621 100644 (file)
@@ -34,6 +34,9 @@ void           _gtk_style_context_coalesce_animation_areas   (GtkStyleContext *c
                                                               GtkWidget       *widget);
 gboolean       _gtk_style_context_check_region_name          (const gchar     *str);
 
+void           _gtk_style_context_get_cursor_color           (GtkStyleContext *context,
+                                                              GdkRGBA         *primary_color,
+                                                              GdkRGBA         *secondary_color);
 
 G_END_DECLS
 
index a41f5b881a886a000ecbc4f6ca2e85ab92e3c541..383f52d1a908d6e897b4b837bda3528a6e46ec32 100644 (file)
@@ -78,6 +78,7 @@
 #include "config.h"
 #include "gtktextdisplay.h"
 #include "gtkwidgetprivate.h"
+#include "gtkstylecontextprivate.h"
 #include "gtkintl.h"
 
 /* DO NOT go putting private headers in here. This file should only
@@ -783,9 +784,9 @@ render_para (GtkTextRenderer    *text_renderer,
               GdkRGBA cursor_color;
               cairo_t *cr = text_renderer->cr;
 
-             /* we draw text using base color on filled cursor rectangle of cursor color
-              * (normally white on black) */
-             _gtk_widget_get_cursor_color (text_renderer->widget, &cursor_color);
+              /* we draw text using base color on filled cursor rectangle of cursor color
+               * (normally white on black) */
+              _gtk_style_context_get_cursor_color (context, &cursor_color, NULL);
 
              cursor_rect.x = x + line_display->x_offset + line_display->block_cursor.x;
              cursor_rect.y = y + line_display->block_cursor.y + line_display->top_margin;
index b98e2c9b2464a2b6b75a3fa04595ac1794203f1c..778fff2b3552dbcc9df49a9e93e1d2e80e31c986 100644 (file)
@@ -93,9 +93,6 @@ gboolean _gtk_widget_get_translation_to_window (GtkWidget      *widget,
                                                 int            *x,
                                                 int            *y);
 
-void  _gtk_widget_get_cursor_color (GtkWidget *widget,
-                                    GdkRGBA  *color);
-
 G_END_DECLS
 
 #endif /* __GTK_WIDGET_PRIVATE_H__ */